package service

import (
	"api-gateway/basic/config"
	__ "api-gateway/basic/proto/rpc"
	"api-gateway/handler/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func EsSearchVideoList(c *gin.Context) {
	var form request.EsSearchVideoList
	if err := c.ShouldBind(&form); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": "参数错误"})
		return
	}
	video, err := config.VideoRpcClient.EsSearchVideoList(c, &__.EsSearchVideoListReq{
		Page:    int64(form.Page),
		Size:    int64(form.Size),
		Keyword: form.Keyword,
		Sort:    form.Sort,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": err.Error()})
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "Es搜索匹配完成", "data": gin.H{
		"list": video.List,
	}})
	return
}
